/*Save replication files in a folder and set that folder as the 
working directory*/

use "Bush Prather Replication Data - Main.dta", clear

/*Figures and Tables from Main Text*/

/*Figures 1 and 2* - see Excel spreadsheets*/

/*Figure 3 - then put data in Excel to make graph*/
tab mainissue_full

/*Table 1*/
ttest effective, by(womentreat) /*Column 1*/
ttest qualified, by(womentreat) /*Column 2*/

/*Table 2*/
prtest contact, by(womentreat) /*Column 1*/
prtest contact if sex==0, by(womentreat) /*Column 2*/
prtest contact if sex==1, by(womentreat) /*Column 3*/

/*Table 3*/
by party, sort: summarize contact /*for "Across Both Treatments*/
prtest contact if party==0, by(womentreat) /*Column 1*/
prtest contact if party==1, by(womentreat) /*Column 2*/
prtest contact if party==2, by(womentreat) /*Column 3*/

/*Table 4*/
by polislam_bin, sort: summarize contact /*for "Across Both Treatments"*/
prtest contact if polislam_bin==0, by(womentreat) /*Column 1*/
prtest contact if polislam_bin==1, by(womentreat) /*Column 2*/



/*Figures and Tables from Appendix*/

/*Table 1*/
summarize contact enumeratorgender sex polislam_bin natsec winner age educ employed rural

/*Table 2*/
*create table1.csv and save in working directory. then run code.*

tab womentreat, gen(dummy_treat)
des dummy_treat*

#delimit ;
set more off;
gen var="";
for any  mean_wom sd_wom mean_man sd_man p_womman N: gen X=.;

local vars=9;
for any enumeratorgender sex polislam_bin natsec winner age educ employed rural 
 \ num 1/`vars':
 replace var="X" if _n==Y \
 reg X dummy_treat2 \
 replace N=e(N) if _n==Y \
 
 test dummy_treat2 =0 \
 replace p_womman =r(p) if _n==Y \
 
sum X if womentreat==0 \
 replace mean_man=r(mean) if _n==Y \
 replace sd_man=r(sd) if _n==Y \
 
sum X if womentreat==1 \
 replace mean_wom=r(mean) if _n==Y \
 replace sd_wom=r(sd) if _n==Y \;

for var p_womman mean* sd*: replace X=round(X, 0.001);
outsheet var mean_wom sd_wom mean_man sd_man p_womman N
 if _n<=`vars' using "table1.csv", comma replace;
 #delimit cr;

 
/*Table 3*/
ttest effective if party==0, by(womentreat) /*Column 1*/
ttest effective if party==1, by(womentreat) /*Column 2*/
ttest effective if party==2, by(womentreat) /*Column 3*/

/*Table 4*/
ttest qualified if party==0, by(womentreat) /*Column 1*/
ttest qualified if party==1, by(womentreat) /*Column 2*/
ttest qualified if party==2, by(womentreat) /*Column 3*/

/*Table 5*/
logit contact womentreat##enumeratorgender /*Column 1*/
logit contact womentreat##enumeratorgender if sex==0 /*Column 2*/
logit contact womentreat##enumeratorgender if sex==1 /*Column 3*/

/*Table 6*/
logit contact womentreat i.governorate /*Column 1*/
logit contact womentreat i.governorate if sex==0 /*Column 2*/
logit contact womentreat i.governorate if sex==1 /*Column 3*/

/*Table 7*/
logit contact womentreat##i.eostreatment /*Column 1*/
logit contact womentreat##i.eostreatment if sex==0 /*Column 2*/
logit contact womentreat##i.eostreatment if sex==1 /*Column 3*/

/*Table 8*/
logit contact womentreat##sex

/*Table 9*/
logit contact womentreat##natsec /*Column 1*/
logit contact womentreat##natsec if sex==0 /*Column 2*/
logit contact womentreat##natsec if sex==1 /*Column 3*/
logit contact womentreat##natsec if party==0 /*Column 4*/
logit contact womentreat##natsec if party==1 /*Column 5*/
logit contact womentreat##natsec if party==2 /*Column 6*/

/*Table 10*/
logit contact womentreat##econ /*Column 1*/
logit contact womentreat##econ if sex==0 /*Column 2*/
logit contact womentreat##econ if sex==1 /*Column 3*/
logit contact womentreat##econ if party==0 /*Column 4*/
logit contact womentreat##econ if party==1 /*Column 5*/
logit contact womentreat##econ if party==2 /*Column 6*/

/*Table 11*/
logit contact womentreat##b2.party /*Column 1*/
logit contact womentreat##b2.party age sex educ employed rural /*Column 2*/

/*Figure 1*/
logit contact womentreat##party age sex educ employed rural
margins womentreat#party, asbalanced
marginsplot, x(party) saving(figure1.gph)

/*Table 12*/
logit contact womentreat##polislam_bin /*Column 1*/
logit contact womentreat##polislam_bin age sex educ employed rural /*Column 2*/


use "Bush Prather Replication Data - Within.dta", clear
/*note: in the code to creat this file, we expanded the dataset (which 
you can see in the data) so for the diff-in-diff analysis there are  
twice the number of observations per respondent (one for wave 1 and 
one for wave 2); therefore, divide the N in half for the total number
of observations in the below tables*/

/*Table 13*/
reg contact womentreat##wave, cluster(id) /*Column 1*/
reg contact womentreat##wave if sex==0, cluster(id) /*Column 2*/
reg contact womentreat##wave if sex==1, cluster(id) /*Column 3*/

/*Table 14*/
reg contact womentreat##wave, cluster(id) /*Column 1*/
margins womentreat#wave /*predicted values*/
margins wave, dydx(womentreat) /*difference and confidence interval*/
reg contact womentreat##wave if sex==0, cluster(id) /*Column 2*/
margins womentreat#wave 
margins wave, dydx(womentreat)
reg contact womentreat##wave if sex==1, cluster(id) /*Column 3*/
margins womentreat#wave 
margins wave, dydx(womentreat)

/*Table 15*/
reg contact womentreat##wave, cluster(id) /*Column 1*/
margins womentreat#wave 
margins wave, dydx(womentreat)
reg contact womentreat##wave if sex==0, cluster(id) /*Column 2*/
margins womentreat#wave 
margins wave, dydx(womentreat)
reg contact womentreat##wave if sex==1, cluster(id) /*Column 3*/
margins womentreat#wave 
margins wave, dydx(womentreat)

/*Table 16*/
reg contact womentreat##wave if party==0, cluster(id) /*Column 1*/
reg contact womentreat##wave if party==1, cluster(id) /*Column 2*/
reg contact womentreat##wave if party==2, cluster(id) /*Column 3*/
